import os, sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from lstack import LinkStack

#更好的做法是用双指针 判断条件为栈是否为空(这才是用到了栈的特性)
def is_out(a, b):
    tmp_st = LinkStack()
    for i in range(len(b)-1):
        if tmp_st.empty():
            for j in range(b[i]):
                tmp_st.push(a[j])
            tmp_st.pop()
        if b[i+1] > b[i]:
            for j in range(b[i], b[i+1]):
                tmp_st.push(a[j])
            tmp_st.pop()
        else:
            if tmp_st.pop() != b[i+1]:
                return False
    return True


if __name__ == "__main__":
    a = [1, 2, 3, 4, 5]
    b = [1, 3, 2, 5, 4]
    print(is_out(a, b))